﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 猜拳
{
    enum Fight
    {
        剪刀,
        石头,
        巴掌
    }
    class Program
    {

        static Random ran = new Random();
        static int winRound = 0;
        static int winRoundOp = 0;

        static int battleCount = 0;
        static Opponent op;
        static Player gamer;
        static void Main(string[] args)
        {

            Console.WriteLine("--------欢迎来猜拳--------");
            Console.WriteLine("*************************");
            Console.WriteLine("********猜拳，开始********");
            Console.WriteLine("*************************");
            Console.WriteLine("出拳规则：1.剪刀  2.石头  3.巴掌");
            Console.WriteLine("输入对战角色：1.刘备 2.孙权 3.曹操");
            string opponenter = Console.ReadLine();
            switch (opponenter)
            {
                case "1":
                    op = new Opponent("刘备");
                    Console.WriteLine("hoho~，旗鼓相当的对手");//可以用继承 把刘备曹操孙权，各些成一个类
                    break;

                case "2":
                    op = new Opponent("孙权");
                    Console.WriteLine("你也想挑战我？？？？");
                    break;

                case "3":
                    op = new Opponent("曹操");
                    Console.WriteLine("?????");
                    break;
            }

            Console.WriteLine("请输入您的姓名");
            string userName = Console.ReadLine();
            gamer = new Player(userName);

            while (true)
            {
                Console.WriteLine("是否开始游戏 Y/N");
                string choose4 = Console.ReadLine();
                while (!choose4.Equals("n", StringComparison.OrdinalIgnoreCase))
                {
                    Battling();


                    Console.WriteLine("你是否还想继续游戏 Y/N");
                    string choose = Console.ReadLine();
                    if (choose.Equals("n", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }



                }
                Console.WriteLine("===========================");
                Console.WriteLine($"{op.Name} vs {gamer.Name}");
                Console.WriteLine("对战次数{0}", battleCount);
                Console.WriteLine(@"姓名                 得分
{0}                 {1}
{2}                 {3}", gamer.Name, winRound, op.Name, winRoundOp);
                if (winRound>winRoundOp)
                {
                    Console.WriteLine("恭喜{0}，赢得胜利",gamer.Name);
                }
                else if (winRound==winRoundOp)
                {
                    Console.WriteLine("唉，{0}怎么这么拉啊",gamer.Name);
                }
                else
                {
                    Console.WriteLine("平局，算你运气好！");
                }
                Console.WriteLine("是否想再来battle一把 Y/N");
                string choose2 = Console.ReadLine();
                if (choose2.Equals("n", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
                else
                {
                    continue;
                }
            }
            Console.WriteLine("结束了，别再来作业来了好吗");








            Console.ReadKey();
        }

        private static void Battling()
        {
            Console.WriteLine("请出拳：1.剪刀  2.石头  3.巴掌");//把出拳写成一个方法

            int throwPunch = int.Parse(Console.ReadLine());
            gamer.ThrowPunch = throwPunch;
            Change(gamer);
            Console.WriteLine(gamer.Rule());//把出拳的内容 原本是数字 换成中文

            op.ThrowPunch = ran.Next(1, 4);
            Change(op);

            Console.WriteLine(op.Rule());
            JudgeRule(gamer, op);
            battleCount++;
        }

        static void Change(BattleInfo a)
        {
            if (a.ThrowPunch == 1)
            {
                a.ThrowPunchChinese = "剪刀";
            }
            else if (a.ThrowPunch == 2)
            {
                a.ThrowPunchChinese = "石头";
            }
            else if (a.ThrowPunch == 3)
            {
                a.ThrowPunchChinese = "布";
            }


        }
        static void JudgeRule(Player a, Opponent b)//前者是玩家，后者人机
        {
            //1.剪刀 2.石头 3.布
            if (a.ThrowPunch == 1)//剪刀
            {
                if (b.ThrowPunch == a.ThrowPunch)
                {
                    Console.WriteLine("和局，真衰！嘿嘿，等着瞧。");
                }
                else if (b.ThrowPunch == 2)
                {
                    Console.WriteLine($"笨蛋，{a.Name}输了");
                    winRoundOp++;
                }
                else if (b.ThrowPunch == 3)
                {
                    Console.WriteLine($"恭喜，{a.Name}胜出");
                    winRound++;
                }
            }

            if (a.ThrowPunch == 2)//石头
            {
                if (b.ThrowPunch == a.ThrowPunch)
                {
                    Console.WriteLine("和局，真衰！嘿嘿，等着瞧。");
                }
                else if (b.ThrowPunch == 3)
                {
                    Console.WriteLine($"笨蛋，{a.Name}输了");
                    winRoundOp++;
                }
                else if (b.ThrowPunch == 1)
                {
                    Console.WriteLine($"恭喜，{a.Name}胜出");
                    winRound++;
                }
            }
            if (a.ThrowPunch == 3)//布
            {
                if (b.ThrowPunch == a.ThrowPunch)
                {
                    Console.WriteLine("和局，真衰！嘿嘿，等着瞧。");
                }
                else if (b.ThrowPunch == 1)
                {
                    Console.WriteLine($"笨蛋，{a.Name}输了");
                    winRoundOp++;
                }
                else if (b.ThrowPunch == 2)
                {
                    Console.WriteLine($"恭喜，{a.Name}胜出");
                    winRound++;
                }
            }


        }
    }
}
